
// Copyright (C) 2009-2011 Luca Piccioni
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

#pragma warning disable 1572, 1573

namespace Derm.OpenGL {

	/// <summary>
	/// Implementation of the OpenGL specification 
	/// </summary>
	public unsafe partial class Glx : ProcLoader
	{

		/// <summary>
		/// Binding for glXBindTexImageEXT function.
		/// </summary>
		/// <param name="dpy">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="drawable">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="buffer">
		/// A <see cref="T:System.Int32"/>.
		/// </param>
		/// <param name="attrib_list">
		/// A <see cref="T:System.Int32*"/>.
		/// </param>
		public static void BindTexImageEXT(IntPtr dpy, IntPtr drawable, int buffer, ref int[] attrib_list) {
			unsafe {
				fixed (int* fp_attrib_list = attrib_list)
				{
					if      (Delegates.pglXBindTexImageEXT != null)
						Delegates.pglXBindTexImageEXT(dpy, drawable, buffer, fp_attrib_list);
					else
						throw new InvalidOperationException("binding point BindTexImageEXT cannot be found");
				}
			}
			LogProc("glXBindTexImageEXT({0}, {1}, {2}, {3})", dpy, drawable, buffer, attrib_list);
		}

		/// <summary>
		/// Binding for glXFreeContextEXT function.
		/// </summary>
		/// <param name="dpy">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="context">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		public static void FreeContextEXT(IntPtr dpy, IntPtr context) {
			if      (Delegates.pglXFreeContextEXT != null)
				Delegates.pglXFreeContextEXT(dpy, context);
			else
				throw new InvalidOperationException("binding point FreeContextEXT cannot be found");
			LogProc("glXFreeContextEXT({0}, {1})", dpy, context);
		}

		/// <summary>
		/// Binding for glXGetContextIDEXT function.
		/// </summary>
		/// <param name="context">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		public static IntPtr GetContextIDEXT(IntPtr context) {
			IntPtr retvalue;
			if      (Delegates.pglXGetContextIDEXT != null)
				retvalue = (Delegates.pglXGetContextIDEXT(context));
			else
				throw new InvalidOperationException("binding point GetContextIDEXT cannot be found");
			LogProc("glXGetContextIDEXT({0}) = {1}", context, retvalue);
			return (retvalue);
		}

		/// <summary>
		/// Binding for glXGetCurrentDisplayEXT function.
		/// </summary>
		public static IntPtr GetCurrentDisplayEXT() {
			IntPtr retvalue;
			if      (Delegates.pglXGetCurrentDisplayEXT != null)
				retvalue = (Delegates.pglXGetCurrentDisplayEXT());
			else
				throw new InvalidOperationException("binding point GetCurrentDisplayEXT cannot be found");
			LogProc("glXGetCurrentDisplayEXT()");
			return (retvalue);
		}

		/// <summary>
		/// Binding for glXImportContextEXT function.
		/// </summary>
		/// <param name="dpy">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="contextID">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		public static IntPtr ImportContextEXT(IntPtr dpy, IntPtr contextID) {
			IntPtr retvalue;
			if      (Delegates.pglXImportContextEXT != null)
				retvalue = (Delegates.pglXImportContextEXT(dpy, contextID));
			else
				throw new InvalidOperationException("binding point ImportContextEXT cannot be found");
			LogProc("glXImportContextEXT({0}, {1}) = {2}", dpy, contextID, retvalue);
			return (retvalue);
		}

		/// <summary>
		/// Binding for glXQueryContextInfoEXT function.
		/// </summary>
		public static void QueryContextInfoEXT() {
			if      (Delegates.pglXQueryContextInfoEXT != null)
				Delegates.pglXQueryContextInfoEXT();
			else
				throw new InvalidOperationException("binding point QueryContextInfoEXT cannot be found");
			LogProc("glXQueryContextInfoEXT()");
		}

		/// <summary>
		/// Binding for glXReleaseTexImageEXT function.
		/// </summary>
		/// <param name="dpy">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="drawable">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="buffer">
		/// A <see cref="T:System.Int32"/>.
		/// </param>
		public static void ReleaseTexImageEXT(IntPtr dpy, IntPtr drawable, int buffer) {
			if      (Delegates.pglXReleaseTexImageEXT != null)
				Delegates.pglXReleaseTexImageEXT(dpy, drawable, buffer);
			else
				throw new InvalidOperationException("binding point ReleaseTexImageEXT cannot be found");
			LogProc("glXReleaseTexImageEXT({0}, {1}, {2})", dpy, drawable, buffer);
		}

		/// <summary>
		/// Binding for glXSwapIntervalEXT function.
		/// </summary>
		/// <param name="dpy">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="drawable">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="interval">
		/// A <see cref="T:System.Int32"/>.
		/// </param>
		public static void SwapIntervalEXT(IntPtr dpy, IntPtr drawable, int interval) {
			if      (Delegates.pglXSwapIntervalEXT != null)
				Delegates.pglXSwapIntervalEXT(dpy, drawable, interval);
			else
				throw new InvalidOperationException("binding point SwapIntervalEXT cannot be found");
			LogProc("glXSwapIntervalEXT({0}, {1}, {2})", dpy, drawable, interval);
		}

		internal static partial class Delegates
		{
			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal unsafe delegate void glXBindTexImageEXT(IntPtr dpy, IntPtr drawable, int buffer, int* attrib_list);
			internal static glXBindTexImageEXT pglXBindTexImageEXT = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal delegate void glXFreeContextEXT(IntPtr dpy, IntPtr context);
			internal static glXFreeContextEXT pglXFreeContextEXT = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal delegate IntPtr glXGetContextIDEXT(IntPtr context);
			internal static glXGetContextIDEXT pglXGetContextIDEXT = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal delegate IntPtr glXGetCurrentDisplayEXT();
			internal static glXGetCurrentDisplayEXT pglXGetCurrentDisplayEXT = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal delegate IntPtr glXImportContextEXT(IntPtr dpy, IntPtr contextID);
			internal static glXImportContextEXT pglXImportContextEXT = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal delegate void glXQueryContextInfoEXT();
			internal static glXQueryContextInfoEXT pglXQueryContextInfoEXT = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal delegate void glXReleaseTexImageEXT(IntPtr dpy, IntPtr drawable, int buffer);
			internal static glXReleaseTexImageEXT pglXReleaseTexImageEXT = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal delegate void glXSwapIntervalEXT(IntPtr dpy, IntPtr drawable, int interval);
			internal static glXSwapIntervalEXT pglXSwapIntervalEXT = null;

		}

		internal static partial class Imports
		{
			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXBindTexImageEXT", ExactSpelling = true)]
			internal extern static unsafe void glXBindTexImageEXT(IntPtr dpy, IntPtr drawable, int buffer, int* attrib_list);

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXFreeContextEXT", ExactSpelling = true)]
			internal extern static void glXFreeContextEXT(IntPtr dpy, IntPtr context);

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXGetContextIDEXT", ExactSpelling = true)]
			internal extern static IntPtr glXGetContextIDEXT(IntPtr context);

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXGetCurrentDisplayEXT", ExactSpelling = true)]
			internal extern static IntPtr glXGetCurrentDisplayEXT();

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXImportContextEXT", ExactSpelling = true)]
			internal extern static IntPtr glXImportContextEXT(IntPtr dpy, IntPtr contextID);

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXQueryContextInfoEXT", ExactSpelling = true)]
			internal extern static void glXQueryContextInfoEXT();

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXReleaseTexImageEXT", ExactSpelling = true)]
			internal extern static void glXReleaseTexImageEXT(IntPtr dpy, IntPtr drawable, int buffer);

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXSwapIntervalEXT", ExactSpelling = true)]
			internal extern static void glXSwapIntervalEXT(IntPtr dpy, IntPtr drawable, int interval);

		}

	}
}
